﻿using System;
using System.IO;

namespace DGRobot
{
    public class LogHelper
    {
        private static readonly string LogDir;
        static LogHelper()
        {
            LogDir = new DirectoryInfo("DebugLog/").FullName;
            if (!string.IsNullOrEmpty(LogDir))
            {
                if (!System.IO.Directory.Exists(LogDir))
                    System.IO.Directory.CreateDirectory(LogDir);
            }
        }
        public static void Log(string message)
        {
            if (Config.IsDebug == false) return;
            if (string.IsNullOrEmpty(LogDir))
                return;
            var logFilePath = Path.Combine(LogDir, string.Format("{0:yyyyMMdd}.txt", DateTime.Today));
            lock (LogDir)
            {
                System.IO.File.AppendAllText(logFilePath, "\r\n" + DateTime.Now.ToString("O") + "\t" + message);
            }
        }
    }
}